package com.chen.blue.converter.business;

import com.chen.blue.domain.dto.business.ContestApplyDto;
import com.chen.blue.domain.dto.business.update.ContestApplyDtoEdit;
import com.chen.blue.domain.model.business.ContestApplyModel;
import com.chen.blue.domain.vo.business.ContestApplyVo;
import org.springframework.cglib.beans.BeanCopier;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Created By CLT On 2024/5/23.
 */
@SuppressWarnings("all")
public abstract class ContestApplyConverter {

    private static final BeanCopier modelToVo = BeanCopier.create(ContestApplyModel.class, ContestApplyVo.class, false);
    private static final BeanCopier dtoToModel = BeanCopier.create(ContestApplyDto.class, ContestApplyModel.class, false);
    private static final BeanCopier dtoEditToModel = BeanCopier.create(ContestApplyDtoEdit.class, ContestApplyModel.class, false);

    /**
     * model->vo
     *
     * @param model
     * @return
     */
    public static ContestApplyVo modelToVo(ContestApplyModel model) {
        if (Objects.isNull(model)) {
            return null;
        }
        ContestApplyVo contestApplyVo = new ContestApplyVo();
        modelToVo.copy(model, contestApplyVo, null);
        return contestApplyVo;
    }

    /**
     * model->volist
     *
     * @param modelList
     * @return
     */
    public static List<ContestApplyVo> modelToVoList(List<ContestApplyModel> modelList) {

        if (modelList.size() == 0) {
            return null;
        }

        List<ContestApplyVo> contestApplyVoList = new ArrayList<>();
        for (ContestApplyModel contestApplyModel : modelList) {
            contestApplyVoList.add(modelToVo(contestApplyModel));
        }

        return contestApplyVoList;

    }

    /**
     * dto->model
     *
     * @param postDto
     * @return
     */
    public static ContestApplyModel dtoToModel(ContestApplyDto contestApplyDto) {

        if (Objects.isNull(contestApplyDto)) {
            return null;
        }

        ContestApplyModel contestApplyModel = new ContestApplyModel();
        dtoToModel.copy(contestApplyDto, contestApplyModel, null);
        return contestApplyModel;

    }

    /**
     * editDto->model
     *
     * @param postDtoEdit
     * @return
     */
    public static ContestApplyModel dtoEditToModel(ContestApplyDtoEdit contestApplyDtoEdit) {

        if (Objects.isNull(contestApplyDtoEdit)) {
            return null;
        }

        ContestApplyModel contestApplyModel = new ContestApplyModel();
        dtoEditToModel.copy(contestApplyDtoEdit, contestApplyModel, null);
        return contestApplyModel;

    }

}
